package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.util.Log
import android.view.View
import com.android.kotlincoroutinemvvmdemo.R

/*
* 风车view2
* */
class WindmillView2 @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val degreeArr = floatArrayOf(0F, 90F, 180F, 270F)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            //拐角---(尖角)
            strokeJoin = Paint.Join.MITER
            color = context.resources.getColor(R.color.color_1E4CC1)
            style = Paint.Style.FILL
        }
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth / 2.0F
            val cy = mHeight / 2.0F
            translate(cx, cy)
            for (degree in degreeArr) {
                save()
                rotate(degree)
                drawArc(
                    0F,
                    -cy / 2,
                    cx,
                    cy / 2,
                    180F,
                    180F,
                    false,
                    mPaint0
                )
                restore()
            }
        }
    }

    companion object {
        const val TAG = "WindmillView2"
    }
}